//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by Apple on 2017/6/3.
//  Copyright © 2017年 KY. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //  便利构造函数扩展UIBarButtonItem的构造对象方式
    //  默认值参数
    convenience init(title: String, imageName: String? = nil, target: Any?, action: Selector) {
        //  使用self调用其它构造函数
        self.init()
        let button = UIButton()
        //  有图片设置按钮图片
        if let imgName = imageName {
            button.setImage(UIImage(named: imgName), for: .normal)
        }
        //  添加点击事件
        button.addTarget(target, action: action, for: .touchUpInside)
        button.setTitle(title, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        //  设置button大小
        button.sizeToFit()
        //  设置自定义按钮
        customView = button
        
    }

}
